<?php
  session_start(); 
  	
  $command_id = $_REQUEST['command_id'];
  $db = new db();
  if($command_id==1)
  {
      if($db->zapisBMI())
      {
          echo "Mereni uspesne vlozeno do databaze.";
      }
  }
  
  class db{
      function zapisBMI()
      {
        $BMI = ($_POST['weight']/ ($_POST['height']/100*$_POST['height']/100));
        $con= mysql_connect("localhost",  "panospet",  "meipei2c" ); 
  			if (!$con) { 
  				echo "Failed to connect to MySQL:".mysql_connect_error(); 
  			}
  			mysql_query("SET NAMES utf8");
  			mysql_select_db("panospet");
         
  	
  	    $sql = "INSERT INTO hodina4_bmi (jmeno,weight,height,bmi) VALUES ('".$_POST['name']."','".$_POST['height']."','".$_POST['weight']."','".$BMI."')";
  	    //mysql_query($sql,$con);
        
  	    if (!mysql_query($sql,$con)) {
  		    echo "Error:".mysql_error();
  		    return false;
          }
          else
          {
              return true;
          }
  			
  	    	    
  	    mysql_close($con);
      
      }
    }
?>